import { defineStore } from 'pinia';
import { KEY_TOKEN } from '@/constant';

interface TokenState {
    token: string;
}

export const useTokenStore = defineStore('token', {
    state: (): TokenState => {
        return {
            token: '',
        };
    },
    actions: {
        remove() {
            this.token = '';
        },
        setToken(token: string) {
            this.token = token;
        },
        isLogin() {
            return this.token !== '';
        },
    },
    persist: {
        storage: sessionStorage,
        key: KEY_TOKEN,
    },
});
